package com.shk.service.imp;

import com.alibaba.dubbo.config.annotation.Service;
import com.shk.constant.MessageConstant;
import com.shk.dao.MemberDao;
import com.shk.entity.Result;
import com.shk.pojo.Member;
import com.shk.service.MemberService;
import com.shk.utils.MD5Utils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;

@Service(interfaceClass = MemberService.class)
@Transactional
public class MemberServiceImpl implements MemberService {
    /*根据电话号码去查询 member是否为空
     * 为空就自动注册为会员
     * 不为空就直接登陆成功*/
    @Autowired
    private MemberDao memberDao;

    @Override
    public Member findByTelephone(String telephone) {
        return memberDao.findMemberByTelephone(telephone);
    }

    @Override
    public void add(Member member) {
        /*判断用户是否设置了密码 如果没有自动生成 加密*/
        String pwd= member.getPassword();
        if(pwd!=null){
            String password = UUID.randomUUID().toString();
            member.setPassword(MD5Utils.md5(password));
        }
        memberDao.add(member);
    }





    //*查询一年的数据 按月分组展示到前端*/
  /*  @Override
    public Map findByOneYear() {
        *//*查出所有的日期  分组进行遍历查询*//*
       List list= memberDao.findRegTime();
       for(Date )
        return null;
    }*/
    @Override
    public List<Integer> findByOneYear(List<String> months) {
        List memberCount = new ArrayList();
        for (String month : months) {
            String regTime1 = month + "-01";
            String regTime = month + "-31"; /*2020-08-31*/
            System.out.println(regTime1+"   "+regTime);
            Integer count = memberDao.findByRegTime(regTime1, regTime);
            System.out.println(count);
            memberCount.add(count);
        }


        return memberCount;
    }


    /**
     * 饼图，根据性别来查询
     * @return
     */
    @Override
    public List<Map<String,Object>> findBySex() {
        List<Map<String,Object>> mapList= memberDao.findBySex();
        return mapList;
    }
}

